package io.lvdaxian.mybatis10.executor.result;

import io.lvdaxian.mybatis10.reflection.factory.ObjectFactory;
import io.lvdaxian.mybatis10.session.ResultContext;
import io.lvdaxian.mybatis10.session.ResultHandler;

import java.util.ArrayList;
import java.util.List;

/**
 * 表示 默认的结果处理事件
 *
 * @author lihh
 */
public class DefaultResultHandler implements ResultHandler {
  
  private final List<Object> list;
  
  public DefaultResultHandler() {
    this.list = new ArrayList<>();
  }
  
  public DefaultResultHandler(ObjectFactory objectFactory) {
    this.list = objectFactory.create(List.class);
  }
  
  
  @Override
  public void handleResult(ResultContext context) {
    list.add(context.getResultObject());
  }
  
  public List<Object> getResultList() {
    return list;
  }
}
